using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using RSteel.DAL;
using RSteel.DAO;


public partial class Contacts : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            int id;
            int.TryParse(Request.QueryString["id"], out id);

            List<Tender> tenders = TenderDao.Instance.GetObjects(5);

            AvailTenders.DataSource = tenders;
            AvailTenders.DataBind();

            TenderList.DataSource = tenders;
            TenderList.DataBind();

            Tender tender = (from tenderList in tenders
                             where tenderList.Id == id
                             select tenderList).SingleOrDefault();
            
            if (tender != null)
            {
                for (int i = 0; i < tenders.Count; i++)
                {
                    if (tender.Id == tenders[i].Id)
                    {
                        TenderList.SelectedIndex = i;
                        break;
                    }
                }
            }
            else
            {
                if (tenders.Count > 0)
                {
                    TenderList.SelectedIndex = 0;
                }
            }
        }
    }
}
